import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.poi.xwpf.usermodel.XWPFRun;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

public class App {
    public static void main(String[] args) {

        File f = new File("E:\\huayun\\gogs\\ioae-console\\src\\main\\java\\com\\chinac\\console\\service");

        File srcs = new File("d:\\console.docx");

        IOFileFilter filter = new IOFileFilter() {

            @Override
            public boolean accept(File file) {
                if (file.isDirectory()) {
                    return true;
                }
                String name = file.getName();
                return name.endsWith(".java");
            }

            @Override
            public boolean accept(File dir, String name) {
                return true;
            }

        };

        Collection<File> fs = FileUtils.listFiles(f, filter, filter);

        Word word = new Word();
        word.createDoc();
        for (Iterator<File> iterator = fs.iterator(); iterator.hasNext(); ) {
            File java = iterator.next();
            System.out.println(java.getAbsolutePath());
            word.createParagraph();
            try {
                List<String> lines = FileUtils.readLines(java, "utf-8");
                for (String l : lines) {
                    // System.out.println(l);
                    XWPFRun run = word.createRun();
                    while (l.startsWith("\t")) {
                        run.addTab();
                        l = l.substring(1);
                    }
                    run.setText(l);
                    run.addBreak();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
        word.write(srcs);
    }
}
